{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "LSTM Autoencoder for Network Anomaly Detection.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true,
      "machine_shape": "hm"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "haDl53nO8Oe6"
      },
      "source": [
        "# **Project: LSTM Autoencoder for Network Anomaly Detection**\n",
        "\n",
        "### **Instructions:**\n",
        "\n",
        "In this project, we will create and train an LSTM-based autoencoder to detect anomalies in the KDD99 network traffic dataset. \n",
        "\n",
        "Note that KDD99 does not include timestamps as a feature. The simplest approach to making these discrete datapoints into time-domain data is to assume that each datapoint occurs at the timestep immediately after the previous datapoint. However, more sophisticated approaches can also be adopted (e.g., grouping by TCP connections). The choice of serialization technique (i.e., conversion into time-domain) is up to you.\n",
        "\n",
        "This project must be implemented in a Jupyer Notebook, and must be compatible with Google Colab (i.e., if you are using a particular library that is not on Colab by default, your notebook must install it via !pip install ... ). Your notebook must also contain a section on performance analysis, where you report the performance of your IDS model via performance metrics and/or plots (similar to Section 5).\n",
        "\n",
        "**A very important note:** You should not expect very high detection rates from your model. "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_2t-Cnfh-ahS"
      },
      "source": [
        "## Read in KDD99 Data Set"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3PFGJcB88M6I",
        "outputId": "210a6453-f368-42ea-a527-931ba330869d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 90
        }
      },
      "source": [
        "#importing required libraries\n",
        "\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import tensorflow as tf\n",
        "from tensorflow import keras\n",
        "import pandas as pd\n",
        "import seaborn as sns\n",
        "import matplotlib.pyplot as plt\n",
        "from sklearn import metrics\n",
        "\n",
        "from tensorflow.keras.utils import get_file\n",
        "try:\n",
        "    path = get_file('kddcup.data_10_percent.gz', origin='http://kdd.ics.uci.edu/databases/kddcup99/kddcup.data_10_percent.gz')\n",
        "except:\n",
        "    print('Error downloading')\n",
        "    raise\n",
        "\n",
        "print(path) "
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/root/.keras/datasets/kddcup.data_10_percent.gz\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n",
            "  import pandas.util.testing as tm\n"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HbiUbM0NPOMy",
        "outputId": "e9cd571b-1323-41b2-a2b7-3051b62d3b1b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# This file is a CSV, just no CSV extension or headers\n",
        "# Download from: http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html\n",
        "df = pd.read_csv(path, header=None)\n",
        "print(\"Read {} rows.\".format(len(df)))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Read 494021 rows.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MX5AmlE6POBA",
        "outputId": "b969e96f-9a43-4ddf-d6ff-9e148f18a877",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 220
        }
      },
      "source": [
        "# The CSV file has no column heads, so add them\n",
        "df.columns = ['duration','protocol_type','service','flag','src_bytes','dst_bytes','land','wrong_fragment','urgent','hot',\n",
        "              'num_failed_logins','logged_in','num_compromised','root_shell', 'su_attempted','num_root','num_file_creations','num_shells',\n",
        "              'num_access_files','num_outbound_cmds','is_host_login','is_guest_login','count','srv_count','serror_rate','srv_serror_rate',\n",
        "              'rerror_rate','srv_rerror_rate','same_srv_rate','diff_srv_rate','srv_diff_host_rate','dst_host_count','dst_host_srv_count',\n",
        "              'dst_host_same_srv_rate','dst_host_diff_srv_rate','dst_host_same_src_port_rate','dst_host_srv_diff_host_rate','dst_host_serror_rate',\n",
        "              'dst_host_srv_serror_rate','dst_host_rerror_rate','dst_host_srv_rerror_rate','outcome']\n",
        "\n",
        "# displaying the contents\n",
        "df.head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>duration</th>\n",
              "      <th>protocol_type</th>\n",
              "      <th>service</th>\n",
              "      <th>flag</th>\n",
              "      <th>src_bytes</th>\n",
              "      <th>dst_bytes</th>\n",
              "      <th>land</th>\n",
              "      <th>wrong_fragment</th>\n",
              "      <th>urgent</th>\n",
              "      <th>hot</th>\n",
              "      <th>num_failed_logins</th>\n",
              "      <th>logged_in</th>\n",
              "      <th>num_compromised</th>\n",
              "      <th>root_shell</th>\n",
              "      <th>su_attempted</th>\n",
              "      <th>num_root</th>\n",
              "      <th>num_file_creations</th>\n",
              "      <th>num_shells</th>\n",
              "      <th>num_access_files</th>\n",
              "      <th>num_outbound_cmds</th>\n",
              "      <th>is_host_login</th>\n",
              "      <th>is_guest_login</th>\n",
              "      <th>count</th>\n",
              "      <th>srv_count</th>\n",
              "      <th>serror_rate</th>\n",
              "      <th>srv_serror_rate</th>\n",
              "      <th>rerror_rate</th>\n",
              "      <th>srv_rerror_rate</th>\n",
              "      <th>same_srv_rate</th>\n",
              "      <th>diff_srv_rate</th>\n",
              "      <th>srv_diff_host_rate</th>\n",
              "      <th>dst_host_count</th>\n",
              "      <th>dst_host_srv_count</th>\n",
              "      <th>dst_host_same_srv_rate</th>\n",
              "      <th>dst_host_diff_srv_rate</th>\n",
              "      <th>dst_host_same_src_port_rate</th>\n",
              "      <th>dst_host_srv_diff_host_rate</th>\n",
              "      <th>dst_host_serror_rate</th>\n",
              "      <th>dst_host_srv_serror_rate</th>\n",
              "      <th>dst_host_rerror_rate</th>\n",
              "      <th>dst_host_srv_rerror_rate</th>\n",
              "      <th>outcome</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>tcp</td>\n",
              "      <td>http</td>\n",
              "      <td>SF</td>\n",
              "      <td>181</td>\n",
              "      <td>5450</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>8</td>\n",
              "      <td>8</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>9</td>\n",
              "      <td>9</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.11</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>normal.</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>tcp</td>\n",
              "      <td>http</td>\n",
              "      <td>SF</td>\n",
              "      <td>239</td>\n",
              "      <td>486</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>8</td>\n",
              "      <td>8</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>19</td>\n",
              "      <td>19</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.05</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>normal.</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>tcp</td>\n",
              "      <td>http</td>\n",
              "      <td>SF</td>\n",
              "      <td>235</td>\n",
              "      <td>1337</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>8</td>\n",
              "      <td>8</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>29</td>\n",
              "      <td>29</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.03</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>normal.</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>tcp</td>\n",
              "      <td>http</td>\n",
              "      <td>SF</td>\n",
              "      <td>219</td>\n",
              "      <td>1337</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>6</td>\n",
              "      <td>6</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>39</td>\n",
              "      <td>39</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.03</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>normal.</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>tcp</td>\n",
              "      <td>http</td>\n",
              "      <td>SF</td>\n",
              "      <td>217</td>\n",
              "      <td>2032</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>6</td>\n",
              "      <td>6</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>49</td>\n",
              "      <td>49</td>\n",
              "      <td>1.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.02</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>normal.</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   duration protocol_type  ... dst_host_srv_rerror_rate  outcome\n",
              "0         0           tcp  ...                      0.0  normal.\n",
              "1         0           tcp  ...                      0.0  normal.\n",
              "2         0           tcp  ...                      0.0  normal.\n",
              "3         0           tcp  ...                      0.0  normal.\n",
              "4         0           tcp  ...                      0.0  normal.\n",
              "\n",
              "[5 rows x 42 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Tkxa5l5xDLRx"
      },
      "source": [
        "## Data Preprocessing"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gNddKIhZPETx",
        "outputId": "7a2e061e-74ea-4514-e87a-65bf2c67de30",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# For now, just drop NA's (rows with missing values)\n",
        "df.dropna(inplace=True,axis=1) \n",
        "df.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(494021, 42)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EY5w2pjiDKA8",
        "outputId": "5499ffbe-82d0-4844-fe0c-862345800ae0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 781
        }
      },
      "source": [
        "df.dtypes"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "duration                         int64\n",
              "protocol_type                   object\n",
              "service                         object\n",
              "flag                            object\n",
              "src_bytes                        int64\n",
              "dst_bytes                        int64\n",
              "land                             int64\n",
              "wrong_fragment                   int64\n",
              "urgent                           int64\n",
              "hot                              int64\n",
              "num_failed_logins                int64\n",
              "logged_in                        int64\n",
              "num_compromised                  int64\n",
              "root_shell                       int64\n",
              "su_attempted                     int64\n",
              "num_root                         int64\n",
              "num_file_creations               int64\n",
              "num_shells                       int64\n",
              "num_access_files                 int64\n",
              "num_outbound_cmds                int64\n",
              "is_host_login                    int64\n",
              "is_guest_login                   int64\n",
              "count                            int64\n",
              "srv_count                        int64\n",
              "serror_rate                    float64\n",
              "srv_serror_rate                float64\n",
              "rerror_rate                    float64\n",
              "srv_rerror_rate                float64\n",
              "same_srv_rate                  float64\n",
              "diff_srv_rate                  float64\n",
              "srv_diff_host_rate             float64\n",
              "dst_host_count                   int64\n",
              "dst_host_srv_count               int64\n",
              "dst_host_same_srv_rate         float64\n",
              "dst_host_diff_srv_rate         float64\n",
              "dst_host_same_src_port_rate    float64\n",
              "dst_host_srv_diff_host_rate    float64\n",
              "dst_host_serror_rate           float64\n",
              "dst_host_srv_serror_rate       float64\n",
              "dst_host_rerror_rate           float64\n",
              "dst_host_srv_rerror_rate       float64\n",
              "outcome                         object\n",
              "dtype: object"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uJH9xUF48Ljr",
        "outputId": "2ee5497e-90c5-48f9-c658-22081ab70eee",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 461
        }
      },
      "source": [
        "df.groupby('outcome')['outcome'].count()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "outcome\n",
              "back.                 2203\n",
              "buffer_overflow.        30\n",
              "ftp_write.               8\n",
              "guess_passwd.           53\n",
              "imap.                   12\n",
              "ipsweep.              1247\n",
              "land.                   21\n",
              "loadmodule.              9\n",
              "multihop.                7\n",
              "neptune.            107201\n",
              "nmap.                  231\n",
              "normal.              97278\n",
              "perl.                    3\n",
              "phf.                     4\n",
              "pod.                   264\n",
              "portsweep.            1040\n",
              "rootkit.                10\n",
              "satan.                1589\n",
              "smurf.              280790\n",
              "spy.                     2\n",
              "teardrop.              979\n",
              "warezclient.          1020\n",
              "warezmaster.            20\n",
              "Name: outcome, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "49nClouCDBWQ"
      },
      "source": [
        "## Encoding numeric and text data:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ignXAw75-o1i"
      },
      "source": [
        "# Encode a numeric column as zscores\n",
        "def encode_numeric_zscore(df, name, mean=None, sd=None):\n",
        "    if mean is None:\n",
        "        mean = df[name].mean()\n",
        "\n",
        "    if sd is None:\n",
        "        sd = df[name].std()\n",
        "\n",
        "    df[name] = (df[name] - mean) / sd\n",
        "    \n",
        "# Encode text values to dummy variables(i.e. [1,0,0],[0,1,0],[0,0,1] for red,green,blue)\n",
        "def encode_text_dummy(df, name):\n",
        "    dummies = pd.get_dummies(df[name])\n",
        "    for x in dummies.columns:\n",
        "        dummy_name = f\"{name}-{x}\"\n",
        "        df[dummy_name] = dummies[x]\n",
        "    df.drop(name, axis=1, inplace=True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zRp2aY8AC-uE"
      },
      "source": [
        "#encoding the feature vector\n",
        "text_col =['protocol_type', 'service', 'flag', 'land', 'logged_in', 'is_host_login', 'is_guest_login', ]\n",
        "\n",
        "for i in df.columns:\n",
        "  if i not in text_col:\n",
        "    if i != 'outcome':\n",
        "      encode_numeric_zscore(df, i)\n",
        "\n",
        "for x in text_col:\n",
        "  encode_text_dummy(df, x)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-TqbJf4IOKGi",
        "outputId": "fff24138-2278-4e12-b46b-fca92c0fe8f7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        }
      },
      "source": [
        "df.dropna(inplace=True,axis=1)\n",
        "df[0:5]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>duration</th>\n",
              "      <th>src_bytes</th>\n",
              "      <th>dst_bytes</th>\n",
              "      <th>wrong_fragment</th>\n",
              "      <th>urgent</th>\n",
              "      <th>hot</th>\n",
              "      <th>num_failed_logins</th>\n",
              "      <th>num_compromised</th>\n",
              "      <th>root_shell</th>\n",
              "      <th>su_attempted</th>\n",
              "      <th>num_root</th>\n",
              "      <th>num_file_creations</th>\n",
              "      <th>num_shells</th>\n",
              "      <th>num_access_files</th>\n",
              "      <th>count</th>\n",
              "      <th>srv_count</th>\n",
              "      <th>serror_rate</th>\n",
              "      <th>srv_serror_rate</th>\n",
              "      <th>rerror_rate</th>\n",
              "      <th>srv_rerror_rate</th>\n",
              "      <th>same_srv_rate</th>\n",
              "      <th>diff_srv_rate</th>\n",
              "      <th>srv_diff_host_rate</th>\n",
              "      <th>dst_host_count</th>\n",
              "      <th>dst_host_srv_count</th>\n",
              "      <th>dst_host_same_srv_rate</th>\n",
              "      <th>dst_host_diff_srv_rate</th>\n",
              "      <th>dst_host_same_src_port_rate</th>\n",
              "      <th>dst_host_srv_diff_host_rate</th>\n",
              "      <th>dst_host_serror_rate</th>\n",
              "      <th>dst_host_srv_serror_rate</th>\n",
              "      <th>dst_host_rerror_rate</th>\n",
              "      <th>dst_host_srv_rerror_rate</th>\n",
              "      <th>outcome</th>\n",
              "      <th>protocol_type-icmp</th>\n",
              "      <th>protocol_type-tcp</th>\n",
              "      <th>protocol_type-udp</th>\n",
              "      <th>service-IRC</th>\n",
              "      <th>service-X11</th>\n",
              "      <th>service-Z39_50</th>\n",
              "      <th>...</th>\n",
              "      <th>service-printer</th>\n",
              "      <th>service-private</th>\n",
              "      <th>service-red_i</th>\n",
              "      <th>service-remote_job</th>\n",
              "      <th>service-rje</th>\n",
              "      <th>service-shell</th>\n",
              "      <th>service-smtp</th>\n",
              "      <th>service-sql_net</th>\n",
              "      <th>service-ssh</th>\n",
              "      <th>service-sunrpc</th>\n",
              "      <th>service-supdup</th>\n",
              "      <th>service-systat</th>\n",
              "      <th>service-telnet</th>\n",
              "      <th>service-tftp_u</th>\n",
              "      <th>service-tim_i</th>\n",
              "      <th>service-time</th>\n",
              "      <th>service-urh_i</th>\n",
              "      <th>service-urp_i</th>\n",
              "      <th>service-uucp</th>\n",
              "      <th>service-uucp_path</th>\n",
              "      <th>service-vmnet</th>\n",
              "      <th>service-whois</th>\n",
              "      <th>flag-OTH</th>\n",
              "      <th>flag-REJ</th>\n",
              "      <th>flag-RSTO</th>\n",
              "      <th>flag-RSTOS0</th>\n",
              "      <th>flag-RSTR</th>\n",
              "      <th>flag-S0</th>\n",
              "      <th>flag-S1</th>\n",
              "      <th>flag-S2</th>\n",
              "      <th>flag-S3</th>\n",
              "      <th>flag-SF</th>\n",
              "      <th>flag-SH</th>\n",
              "      <th>land-0</th>\n",
              "      <th>land-1</th>\n",
              "      <th>logged_in-0</th>\n",
              "      <th>logged_in-1</th>\n",
              "      <th>is_host_login-0</th>\n",
              "      <th>is_guest_login-0</th>\n",
              "      <th>is_guest_login-1</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>-0.067792</td>\n",
              "      <td>-0.002879</td>\n",
              "      <td>0.138664</td>\n",
              "      <td>-0.04772</td>\n",
              "      <td>-0.002571</td>\n",
              "      <td>-0.044136</td>\n",
              "      <td>-0.009782</td>\n",
              "      <td>-0.005679</td>\n",
              "      <td>-0.010552</td>\n",
              "      <td>-0.004676</td>\n",
              "      <td>-0.00564</td>\n",
              "      <td>-0.011232</td>\n",
              "      <td>-0.009919</td>\n",
              "      <td>-0.027632</td>\n",
              "      <td>-1.521415</td>\n",
              "      <td>-1.156639</td>\n",
              "      <td>-0.464089</td>\n",
              "      <td>-0.46352</td>\n",
              "      <td>-0.24796</td>\n",
              "      <td>-0.248631</td>\n",
              "      <td>0.536987</td>\n",
              "      <td>-0.255243</td>\n",
              "      <td>-0.203633</td>\n",
              "      <td>-3.451532</td>\n",
              "      <td>-1.694313</td>\n",
              "      <td>0.599396</td>\n",
              "      <td>-0.282866</td>\n",
              "      <td>-1.022076</td>\n",
              "      <td>-0.158629</td>\n",
              "      <td>-0.464417</td>\n",
              "      <td>-0.463202</td>\n",
              "      <td>-0.252039</td>\n",
              "      <td>-0.249464</td>\n",
              "      <td>normal.</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>-0.067792</td>\n",
              "      <td>-0.002820</td>\n",
              "      <td>-0.011578</td>\n",
              "      <td>-0.04772</td>\n",
              "      <td>-0.002571</td>\n",
              "      <td>-0.044136</td>\n",
              "      <td>-0.009782</td>\n",
              "      <td>-0.005679</td>\n",
              "      <td>-0.010552</td>\n",
              "      <td>-0.004676</td>\n",
              "      <td>-0.00564</td>\n",
              "      <td>-0.011232</td>\n",
              "      <td>-0.009919</td>\n",
              "      <td>-0.027632</td>\n",
              "      <td>-1.521415</td>\n",
              "      <td>-1.156639</td>\n",
              "      <td>-0.464089</td>\n",
              "      <td>-0.46352</td>\n",
              "      <td>-0.24796</td>\n",
              "      <td>-0.248631</td>\n",
              "      <td>0.536987</td>\n",
              "      <td>-0.255243</td>\n",
              "      <td>-0.203633</td>\n",
              "      <td>-3.297081</td>\n",
              "      <td>-1.600009</td>\n",
              "      <td>0.599396</td>\n",
              "      <td>-0.282866</td>\n",
              "      <td>-1.146736</td>\n",
              "      <td>-0.158629</td>\n",
              "      <td>-0.464417</td>\n",
              "      <td>-0.463202</td>\n",
              "      <td>-0.252039</td>\n",
              "      <td>-0.249464</td>\n",
              "      <td>normal.</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>-0.067792</td>\n",
              "      <td>-0.002824</td>\n",
              "      <td>0.014179</td>\n",
              "      <td>-0.04772</td>\n",
              "      <td>-0.002571</td>\n",
              "      <td>-0.044136</td>\n",
              "      <td>-0.009782</td>\n",
              "      <td>-0.005679</td>\n",
              "      <td>-0.010552</td>\n",
              "      <td>-0.004676</td>\n",
              "      <td>-0.00564</td>\n",
              "      <td>-0.011232</td>\n",
              "      <td>-0.009919</td>\n",
              "      <td>-0.027632</td>\n",
              "      <td>-1.521415</td>\n",
              "      <td>-1.156639</td>\n",
              "      <td>-0.464089</td>\n",
              "      <td>-0.46352</td>\n",
              "      <td>-0.24796</td>\n",
              "      <td>-0.248631</td>\n",
              "      <td>0.536987</td>\n",
              "      <td>-0.255243</td>\n",
              "      <td>-0.203633</td>\n",
              "      <td>-3.142630</td>\n",
              "      <td>-1.505706</td>\n",
              "      <td>0.599396</td>\n",
              "      <td>-0.282866</td>\n",
              "      <td>-1.188290</td>\n",
              "      <td>-0.158629</td>\n",
              "      <td>-0.464417</td>\n",
              "      <td>-0.463202</td>\n",
              "      <td>-0.252039</td>\n",
              "      <td>-0.249464</td>\n",
              "      <td>normal.</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>-0.067792</td>\n",
              "      <td>-0.002840</td>\n",
              "      <td>0.014179</td>\n",
              "      <td>-0.04772</td>\n",
              "      <td>-0.002571</td>\n",
              "      <td>-0.044136</td>\n",
              "      <td>-0.009782</td>\n",
              "      <td>-0.005679</td>\n",
              "      <td>-0.010552</td>\n",
              "      <td>-0.004676</td>\n",
              "      <td>-0.00564</td>\n",
              "      <td>-0.011232</td>\n",
              "      <td>-0.009919</td>\n",
              "      <td>-0.027632</td>\n",
              "      <td>-1.530798</td>\n",
              "      <td>-1.164758</td>\n",
              "      <td>-0.464089</td>\n",
              "      <td>-0.46352</td>\n",
              "      <td>-0.24796</td>\n",
              "      <td>-0.248631</td>\n",
              "      <td>0.536987</td>\n",
              "      <td>-0.255243</td>\n",
              "      <td>-0.203633</td>\n",
              "      <td>-2.988179</td>\n",
              "      <td>-1.411402</td>\n",
              "      <td>0.599396</td>\n",
              "      <td>-0.282866</td>\n",
              "      <td>-1.188290</td>\n",
              "      <td>-0.158629</td>\n",
              "      <td>-0.464417</td>\n",
              "      <td>-0.463202</td>\n",
              "      <td>-0.252039</td>\n",
              "      <td>-0.249464</td>\n",
              "      <td>normal.</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>-0.067792</td>\n",
              "      <td>-0.002842</td>\n",
              "      <td>0.035214</td>\n",
              "      <td>-0.04772</td>\n",
              "      <td>-0.002571</td>\n",
              "      <td>-0.044136</td>\n",
              "      <td>-0.009782</td>\n",
              "      <td>-0.005679</td>\n",
              "      <td>-0.010552</td>\n",
              "      <td>-0.004676</td>\n",
              "      <td>-0.00564</td>\n",
              "      <td>-0.011232</td>\n",
              "      <td>-0.009919</td>\n",
              "      <td>-0.027632</td>\n",
              "      <td>-1.530798</td>\n",
              "      <td>-1.164758</td>\n",
              "      <td>-0.464089</td>\n",
              "      <td>-0.46352</td>\n",
              "      <td>-0.24796</td>\n",
              "      <td>-0.248631</td>\n",
              "      <td>0.536987</td>\n",
              "      <td>-0.255243</td>\n",
              "      <td>-0.203633</td>\n",
              "      <td>-2.833728</td>\n",
              "      <td>-1.317098</td>\n",
              "      <td>0.599396</td>\n",
              "      <td>-0.282866</td>\n",
              "      <td>-1.209066</td>\n",
              "      <td>-0.158629</td>\n",
              "      <td>-0.464417</td>\n",
              "      <td>-0.463202</td>\n",
              "      <td>-0.252039</td>\n",
              "      <td>-0.249464</td>\n",
              "      <td>normal.</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>...</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>5 rows × 121 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "   duration  src_bytes  ...  is_guest_login-0  is_guest_login-1\n",
              "0 -0.067792  -0.002879  ...                 1                 0\n",
              "1 -0.067792  -0.002820  ...                 1                 0\n",
              "2 -0.067792  -0.002824  ...                 1                 0\n",
              "3 -0.067792  -0.002840  ...                 1                 0\n",
              "4 -0.067792  -0.002842  ...                 1                 0\n",
              "\n",
              "[5 rows x 121 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yTki_IrySDcY",
        "outputId": "a968481a-6032-4322-bbd1-f41a7709c756",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "df['protocol_type-tcp'].unique()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([1, 0], dtype=uint8)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WQULPidDTeiP",
        "outputId": "8f5cca59-3a24-48a7-ea37-5ba0c90a9a26",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        }
      },
      "source": [
        "normal_mask = df['outcome']=='normal.'\n",
        "attack_mask = df['outcome']!='normal.'\n",
        "\n",
        "df.drop('outcome',axis=1,inplace=True)\n",
        "\n",
        "df_normal = df[normal_mask]\n",
        "df_attack = df[attack_mask]\n",
        "\n",
        "print(f\"Normal count: {len(df_normal)}\")\n",
        "print(f\"Attack count: {len(df_attack)}\")"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Normal count: 97278\n",
            "Attack count: 396743\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sS_snYlWTgCY"
      },
      "source": [
        "# This is the numeric feature vector, as it goes to the neural net\n",
        "x_normal = df_normal.values\n",
        "x_attack = df_attack.values"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HQMsrgUoUfbr",
        "outputId": "24ada8c4-55d3-443b-f309-adea5f76d50a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        }
      },
      "source": [
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "x_normal_train, x_normal_test = train_test_split(x_normal, test_size=0.3, random_state=12)\n",
        "\n",
        "print(f\"Normal train count: {len(x_normal_train)}\")\n",
        "print(f\"Normal test count: {len(x_normal_test)}\")"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Normal train count: 68094\n",
            "Normal test count: 29184\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ijFqQmC9Ul-I",
        "outputId": "d8289d85-9616-4aac-b50b-0030893f2e8f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "x_normal_train.shape, x_normal_test.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "((68094, 120), (29184, 120))"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SQLElOnrXdNc"
      },
      "source": [
        "#Scaling the dataset \n",
        "from sklearn.preprocessing import StandardScaler\n",
        "\n",
        "sc = StandardScaler()\n",
        "\n",
        "x_normal_train = sc.fit_transform(x_normal_train)\n",
        "x_normal_test = sc.fit_transform(x_normal_test)\n",
        "x_normal = sc.fit_transform(x_normal)\n",
        "x_attack = sc.fit_transform(x_attack)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hGz3EXfypegL"
      },
      "source": [
        "We already know that the KDD99 dataset doesn't include timestamps as a feature. So, lets consider simplest approach to making these datapoints into time-domain data i.e., to assume that each datapoint occurs at the timestep immediately after the previous datapoint."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eiPGMrHOYL57"
      },
      "source": [
        "x_normal_train = pd.DataFrame(x_normal_train)\n",
        "x_normal_test = pd.DataFrame(x_normal_test)\n",
        "x_attack = pd.DataFrame(x_attack)\n",
        "x_normal = pd.DataFrame(x_normal)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mexyPTQ8Tf8Z"
      },
      "source": [
        "#function to convert to time domain dataset\n",
        "def create_dataset(X, time_steps):\n",
        "    Xs = []\n",
        "    for i in range(len(X) - time_steps):\n",
        "        v = X.iloc[i:(i + time_steps)].values\n",
        "        Xs.append(v)\n",
        "    return np.array(Xs)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jGJNP1LKTf2H",
        "outputId": "d960b18c-28cc-47c8-e11e-5c6dff2d66b9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# reshape to [samples, time_steps, n_features]\n",
        "\n",
        "TIME_STEPS = 1\n",
        "Xnormal_train = create_dataset(x_normal_train, TIME_STEPS)\n",
        "print(Xnormal_train.shape)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(68093, 1, 120)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vgaJUwHYV0HP",
        "outputId": "eb7b9f28-ecfa-4042-ea1d-8a673e960706",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "Xnormal_test = create_dataset(x_normal_test, TIME_STEPS)\n",
        "print(Xnormal_test.shape)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(29183, 1, 120)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dNUaZvSczcLE",
        "outputId": "bb9aeee5-2707-4418-dba0-87010b46b1cb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "Xattack = create_dataset(x_attack, TIME_STEPS)\n",
        "print(Xattack.shape)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(396742, 1, 120)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "i6Hx1JaVEQpn",
        "outputId": "9ef10339-5116-413b-d1a0-dab68d456b6b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "Xnormal = create_dataset(x_normal,TIME_STEPS)\n",
        "print(Xattack.shape)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "(396742, 1, 120)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "s1LwRkvRjUjU"
      },
      "source": [
        "## LSTM Autoencoder Model Architecture:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oDKT-smgCaOu",
        "outputId": "7d2ecaed-593c-4fbf-cd1b-97d06be7a845",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 372
        }
      },
      "source": [
        "model = keras.Sequential()\n",
        "model.add(keras.layers.LSTM(units=64, input_shape=(Xnormal_train.shape[1], Xnormal_train.shape[2])))\n",
        "model.add(keras.layers.Dropout(rate=0.5))\n",
        "model.add(keras.layers.RepeatVector(n=Xnormal_train.shape[1]))\n",
        "model.add(keras.layers.LSTM(units=32, return_sequences=True))\n",
        "model.add(keras.layers.Dropout(rate=0.2))\n",
        "model.add(keras.layers.TimeDistributed(keras.layers.Dense(units=Xnormal_train.shape[2])))\n",
        "\n",
        "model.compile(loss='mae', optimizer='adam', metrics=['accuracy'])\n",
        "model.summary()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Model: \"sequential\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "lstm (LSTM)                  (None, 64)                47360     \n",
            "_________________________________________________________________\n",
            "dropout (Dropout)            (None, 64)                0         \n",
            "_________________________________________________________________\n",
            "repeat_vector (RepeatVector) (None, 1, 64)             0         \n",
            "_________________________________________________________________\n",
            "lstm_1 (LSTM)                (None, 1, 32)             12416     \n",
            "_________________________________________________________________\n",
            "dropout_1 (Dropout)          (None, 1, 32)             0         \n",
            "_________________________________________________________________\n",
            "time_distributed (TimeDistri (None, 1, 120)            3960      \n",
            "=================================================================\n",
            "Total params: 63,736\n",
            "Trainable params: 63,736\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rwif8JwDh2nY"
      },
      "source": [
        "## LSTM Autoencoder Model Training:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "R6ppHeDjlEKI",
        "outputId": "ba059b04-b23f-4e3f-e64b-ab76b0003434",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 570
        }
      },
      "source": [
        "history = model.fit(\n",
        "    Xnormal_train, Xnormal_train,\n",
        "    epochs=15,\n",
        "    batch_size=128,\n",
        "    validation_split=0.2, \n",
        "    shuffle = False\n",
        ")"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Epoch 1/15\n",
            "426/426 [==============================] - 3s 7ms/step - loss: 0.1076 - accuracy: 0.1754 - val_loss: 0.0692 - val_accuracy: 0.2731\n",
            "Epoch 2/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0662 - accuracy: 0.3358 - val_loss: 0.0496 - val_accuracy: 0.2849\n",
            "Epoch 3/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0585 - accuracy: 0.3647 - val_loss: 0.0471 - val_accuracy: 0.2991\n",
            "Epoch 4/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0554 - accuracy: 0.3761 - val_loss: 0.0460 - val_accuracy: 0.3019\n",
            "Epoch 5/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0532 - accuracy: 0.3750 - val_loss: 0.0449 - val_accuracy: 0.3290\n",
            "Epoch 6/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0518 - accuracy: 0.3865 - val_loss: 0.0444 - val_accuracy: 0.3288\n",
            "Epoch 7/15\n",
            "426/426 [==============================] - 2s 5ms/step - loss: 0.0508 - accuracy: 0.4006 - val_loss: 0.0434 - val_accuracy: 0.3790\n",
            "Epoch 8/15\n",
            "426/426 [==============================] - 2s 5ms/step - loss: 0.0496 - accuracy: 0.4457 - val_loss: 0.0420 - val_accuracy: 0.3878\n",
            "Epoch 9/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0485 - accuracy: 0.4603 - val_loss: 0.0411 - val_accuracy: 0.3881\n",
            "Epoch 10/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0477 - accuracy: 0.4695 - val_loss: 0.0404 - val_accuracy: 0.3935\n",
            "Epoch 11/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0472 - accuracy: 0.4712 - val_loss: 0.0399 - val_accuracy: 0.3981\n",
            "Epoch 12/15\n",
            "426/426 [==============================] - 2s 5ms/step - loss: 0.0468 - accuracy: 0.4749 - val_loss: 0.0395 - val_accuracy: 0.4021\n",
            "Epoch 13/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0463 - accuracy: 0.4757 - val_loss: 0.0394 - val_accuracy: 0.4060\n",
            "Epoch 14/15\n",
            "426/426 [==============================] - 2s 5ms/step - loss: 0.0459 - accuracy: 0.4869 - val_loss: 0.0390 - val_accuracy: 0.4085\n",
            "Epoch 15/15\n",
            "426/426 [==============================] - 2s 6ms/step - loss: 0.0453 - accuracy: 0.5265 - val_loss: 0.0380 - val_accuracy: 0.4838\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aWaAqcwx4Axp",
        "outputId": "10e0292d-5e02-44c0-fabf-e516ad5a5f00",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        }
      },
      "source": [
        "plt.plot(history.history['loss'], label='train')\n",
        "plt.plot(history.history['val_loss'], label='validation')\n",
        "plt.legend();"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD5CAYAAAAp8/5SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA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uMdSBTKgXrgOber6WkRyYh3UJGo6nHgMZyW2wmgSVV/Gd+oojJbVU+40yeB2fEMZhz+E/DzeAcxGhFZCxxX1XdiuV+vJPoZSUQygX8FvqSqzfGOJxIRuQk4rao74h1LlHzACuA7qrocaGP6dC0M4/Ztr8WpnIqBDBG5L75RjY8692dP+3u0ReS/4XSZPh/vWEYiIunAXwFfi/W+vZLojwNlIfOl7rJpS0T8OEn+eVX9t3jHM4qrgFtE5AhOl9ifiMiP4hvSqGqBWlUdOEPaiJP4p6MPAe+rar2q9gD/BvxxnGOKxikRKQJwv0/HOZ5RicgDwE3AvTq9Hxy6CKfSf8f9eysF3hKRORPdsVcS/TbgEhEpF5EUnAtam+Ic04hERHD6kPeq6uPxjmc0qvqXqlqqqvNx/ru+oqrTttWpqieBGhFZ6C5aDeyJY0ijOQasEpF099/EaqbpheMwm4D73en7gZfiGMuoRGQNTrfjLaraHu94RqOq76rqLFWd7/691QIr3H/TE+KJRO9ebHkI2ILzh/KiqlbHN6pRXQV8Aqd1vNP93BjvoDzkPwPPi8guYBnw/8c5nojcs46NwFvAuzh/j9PqcX0RWQ/8AVgoIrUi8mngUeDDInIA56zk0XjGOGCEWL8NZAEvu39n341rkCFGiHdyjjW9z2SMMcZMlCda9MYYY0Zmid4YYzzOEr0xxnicJXpjjPE4S/TGGONxluiNMcbjLNEbY4zH/T+ihOT42f8HPQAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hNCyk6cdiEQy"
      },
      "source": [
        "## Model Evaluation:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7nGehivhNKXt",
        "outputId": "bb3d763e-230c-4db2-8bff-dc76dd86c17b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "X_train_pred = model.predict(Xnormal_train)\n",
        "\n",
        "train_mae_loss = np.mean(np.abs(X_train_pred - Xnormal_train), axis=1)\n",
        "train_mae_loss.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(68093, 120)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vngf35TONPyE",
        "outputId": "67023318-79a0-4c88-afea-a45a9398af29",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 268
        }
      },
      "source": [
        "sns.distplot(train_mae_loss, bins=10, kde=True);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD7CAYAAABjVUMJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAW8UlEQVR4nO3df4xV5Z3H8fdnZmCwVrDC6Lr86ODCpkVNuzqL/mGbtEaLTduxKUasqfxByjaWZDeNydI0Epe12dBka9LImqULu5SsC4au6WyKpba0adqslMGi/FDaEanM6FZApKLlxzDf/eM+g5frHe4ZZoYZ7vN5JTf3nOc855nn4czcD+fHPUcRgZmZ5adhtDtgZmajwwFgZpYpB4CZWaYcAGZmmXIAmJllygFgZpapQgEgaZ6kvZK6JC2tsrxZ0oa0fKuk1orlMyQdk/RA0TbNzGxk1QwASY3ASuAOYA5wj6Q5FdUWAUciYhbwCLCiYvm3gacG2aaZmY2gpgJ15gJdEbEPQNJ6oB3YU1anHXgoTW8EHpWkiAhJdwIvA28Pss33mDJlSrS2thbospmZ9du+ffuhiGipLC8SAFOBA2Xz3cBNA9WJiF5JR4HJko4Dfw/cBjxQrf452nyP1tZWOjs7C3TZzMz6Sfp9tfKRPgn8EPBIRBw73wYkLZ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NpXX1XY9xzjH3naNiLp9UTrB/BJwDTAeeA6YM9r9GuYx7gemVJR9C1iappcCK0a7n+cxro8DNwC7ao0L+DTwFKXv69wMbB3t/g9xnA8BD1SpOyf9DjcDM9PvduNoj2EQY70auCFNXwb8No2prrbrOcY55rZrve8BnLmNRUScBPpvOVHv2oG1aXotcOco9uW8RMQvKF1RVm6gcbUD34uSZ4DLJV19YXo6NAOMcyBnbq0SES8D5bdWGfMi4rWIeDZNvwW8QOnOAHW1Xc8xzoGM2nat9wCodhuLc22Ii1EAP5a0PX1rGuCqiHgtTf8fcNXodG3YDTSuetzOS9JhjzVlh/DqZpwq3TH4r4Ct1PF2rRgnjLHtWu8BkINbIuIGSndW/aqkj5cvjNI+Zt1d6lWv40oeA/4C+CjwGvDPo9ud4SXp/cD3gb+LiLNuqlVP27XKOMfcdq33AChyG4uLWkT0pPfXgScp7Tr+oX9XOb3Xyz2vBxpXXW3niPhDRJyOiD5Kt63qPxxw0Y9T0jhKH4r/GRH/nYrrbrtWG+dY3K71HgB1fcsJSZdKuqx/Grgd2MXZt+ZYCPxgdHo47AYaVwdwX7pq5GbgaNkhhYtOxXHuz1PapjDwrVUuCpJE6a4BL0TEt8sW1dV2HWicY3K7jvYZ85F+UbqS4LeUzqx/Y7T7M8xju4bS1QPPAbv7x0fpVtw/BX4H/AS4YrT7eh5j+y9Ku8mnKB0TXTTQuChdJbIybeOdQNto93+I41yXxvE8pQ+Hq8vqfyONcy9wx2j3f5BjvYXS4Z3ngR3p9el6267nGOeY267+JrCZWabq/RCQmZkNwAFgZpYpB4CZWaYcAGZmmXIAmJllygFgZpYpB4CZWaYcAGZmmfp/EVRjviiY3xsAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "H9bfyAXzNUVX",
        "outputId": "83ca021f-d1a7-49eb-c193-f4aa695f2a54",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "X_test_pred = model.predict(Xnormal_test)\n",
        "\n",
        "test_mae_loss = np.mean(np.abs(X_test_pred - Xnormal_test), axis=1)\n",
        "test_mae_loss.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(29183, 120)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "C9Hv-Lp7Ohx0",
        "outputId": "a9e18269-96d9-41ce-f222-0178b68e3991",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        }
      },
      "source": [
        "sns.distplot(test_mae_loss, bins=10, kde=True);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAATK0lEQVR4nO3df6zd9X3f8eeLe7EZITGNuc1SILUzk05mjRJ251RTyKaxZCZq42SF1SRS2YbEotXSqijqXEVDDHV/uNOCNGEt8wQa85pCS5rtTnVF15Em2pY4vhDzw6ReLj8a7NLE2MQd4YcxvPfH+To5nF37nmsf+9zL5/mQju73+/l+zve8z4evX+ec7y9SVUiS3vzOG3cBkqRzw8CXpEYY+JLUCANfkhph4EtSIybHXcCgSy65pNasWTPuMiRpWXnwwQefq6qpU/VZcoG/Zs0aZmdnx12GJC0rSf50oT5D7dJJsjHJ/iRzSbbOs3xlknu75buTrOlb9t4kX0+yL8mjSS5YzJuQJI3GgoGfZALYDlwLrAduSLJ+oNtNwPNVtQ64HdjWPXcS+M/Ap6vqSuBvA6+OrHpJ0tCG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sf0/slcsLaJN9K8tUkV4+rqHnMtw0shzG+GvheVX2nr23RY/xmCfxlI8lFwJeAX62qvwD+HfBXgPcBz9L72baUfLCqrgKuBX4lyYf6F1bv9+WSO7e3u0jwY8Dvdk1LfZx/ZKmO6ckk+Ry962x+q2t6FnhXVb0f+AzwxSRvG1d9fZbNNjCPG3jjl5fTGuM3S+Avi1s4JDmfXtj/VlX9HkBVfa+qXquq14H/wBh+Sp5KVR3s/n4f+DK9+r53YrdC9/f746vwpK4FHqqq78HSH2dOPqZLettO8g+Bnwc+1X1Q0e0aOdxNP0hvn/h7xlZk5xTbwFIf40ng7wP3nmg73TF+swT+MLd/GKtuH9ydwLer6vN97f37Yz8BPDb43HFJ8pYkbz0xTe8g3WO88VYaNwL/dTwVntIbvhEt5XHunGxMZ4Bf7s7W+TngaN+un7FKshH4NeBjVfViX/tUev8fDZK8m94tVZ4cT5U/doptYKnfAubvAn9SVQdONJz2GJ/rI9Fn8Qj3R+md+fIE8Llx1zNPfR+k9zP9EWBv9/gosBN4tGufAd457lr7an43vbMXHgb2nRhXere+/h/Ad4A/At4+7loH6n4LvZv3reprWzLjTO+D6FngVXr7i2862ZjSOztne7ddPwpML6Ga5+jt+z6xPX+h6/uL3fayF3gI+IUlUu9JtwHgc90Y7weuXSpj3LX/R+DTA31Pa4y9tYIkNeLNsktHkrQAA1+SGmHgS1IjDHxJaoSBL0mNMPAlqREGviQ14v8BAqnsnpU8mFMAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XGZLWcy-Oq8a",
        "outputId": "15038a70-515b-4ec0-d77d-58ad2f948542",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "X_normal_pred = model.predict(Xnormal)\n",
        "\n",
        "normal_mae_loss = np.mean(np.abs(X_normal_pred - Xnormal), axis=1)\n",
        "normal_mae_loss.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(97277, 120)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rp1Bqz3SO10M",
        "outputId": "541ec672-4871-4be4-972e-b3428f74406d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        }
      },
      "source": [
        "sns.distplot(normal_mae_loss, bins=10, kde=True);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD4CAYAAADlwTGnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAT7ElEQVR4nO3df6xf9X3f8eeLe7EhJIHFOBm1oXaGq8qQLUs8J5PSSguCmqitqQqKM1T4A9XbEkubov7hKArKUPoHk7ZIUVA6MugIagaUjeVOdUaTkapKpzi+JAZsqNsLIcUODeZnQld+2Lz3x/eYfPnme32P8b2+vv48H+Kr7zmf8zmf+/5wrr8vf8/3fI9TVUiS2nPaYhcgSVocBoAkNcoAkKRGGQCS1CgDQJIaNbnYBRyLc889t9asWbPYZUjSknL//fc/XVUrR9uXVACsWbOG6enpxS5DkpaUJD8c1+4pIElqlAEgSY0yACSpUQaAJDXKAJCkRhkAktQoA0CSGmUASFKjDABJatSS+ibw8fjqzr9ZlJ/7Lz9wwaL8XEmai+8AJKlRBoAkNcoAkKRGGQCS1CgDQJIaZQBIUqMMAElqlAEgSY0yACSpUb0CIMmmJPuSzCTZPmb78iR3dtt3JlnTtW9Msrt7PJDkt/qOKUlaWHMGQJIJ4CbgcmA98LEk60e6XQc8V1UXAp8Hbuza9wAbquq9wCbgP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ev9VJVf0AGL7VyaKoqier6nvd8k+BRxh8+37JHIejzGE2J+NxqKo6cv+Z07tHAR9mcLsc+PnjcOT43A1ckiz8zVZO9QAYdxuLo/0inUwK+NMk93e3wwB4V1U92S3/LfCuxSntmMxW81I7Ntu6UyS3Dp16O6nn0J1G+KcM/va5JI/DyBxgCR2HJBNJdgNPAd9g8M7k+ao61HUZrvMNt9MBjtxOZ0Gd6gGwlH2oqt4HXA58IsmvDm+swXvFJXUN71KsufMl4B8B7wWeBP7j4pYztyRvBf478O+q6ifD25bKcRgzhyV1HKrqcFW9l8GdDjYCv7zIJf2cUz0AluwtJ6rqQPf8FHAPg1+gHx95e949P7V4FfY2W81L5thU1Y+7P8yvAV/mZ6cXTso5JDmdwQvnH1XV/+ial9RxGDeHpXYcjqiq54FvAf+cwSm2I1/AHa5zttvpLKhTPQCW5C0nkpyV5G1HloHLgD288ZYb1wJfW5wKj8lsNU8B13RXoXwQeGHoFMVJZeSc+G8xOBYw+61OFk133vgW4JGq+k9Dm5bMcZhtDkvsOKxMck63fCaDf/vkEQZBcGXXbfQ4jLudzsJazE/KT8SDwVUOf8Xg/NunF7uenjW/m8FVDQ8Ae4/UzeCc4P8B/hr4JvCOxa51pO7/xuCt+asMzm9eN1vNDK6SuKk7Lg8BGxa7/qPM4fauxgcZ/EE9b6j/p7s57AMuPwnq/xCD0zsPAru7x0eW0nE4yhyW0nH4x8D3u1r3ANd37e9mEE4zwB8Dy7v2M7r1mW77u09End4KQpIadaqfApIkzcIAkKRGGQCS1CgDQJIaZQBIUqMMAElqlAEgSY36/1LTh0cB3N93AAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SSByT_hdO_rI",
        "outputId": "47421e55-f33b-4e06-c3e8-7818f93d0b34",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "X_attack_pred = model.predict(Xattack)\n",
        "\n",
        "attack_mae_loss = np.mean(np.abs(X_attack_pred - Xattack), axis=1)\n",
        "attack_mae_loss.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(396742, 120)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jhxKLUoIPAaO",
        "outputId": "85b6f24b-4e46-4f0b-db9d-366cf3c56c89",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 265
        }
      },
      "source": [
        "sns.distplot(attack_mae_loss, bins=10, kde=True);"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD4CAYAAADlwTGnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAW9klEQVR4nO3df5Bd9X3e8fejXSQDroUtdjy2pHSVSo5ncWugOzLUHo9r1SDSNGJamIjUDZNqqj8Krd3Gk4p6YFocpmXGDbYHzFRjlFDqWGDFabauGjmx8B9MG6HlR2wkkL0R2JKKw1rI4ocj5BVP/zhf7MvlrvZotWh39X1e4x2d8z2fc/bzFdf30T3n3nNlm4iIqM+C2W4gIiJmRwIgIqJSCYCIiEolACIiKpUAiIioVP9sN3AqLrzwQg8ODs52GxER88ojjzzyI9sD3ePzKgAGBwcZHR2d7TYiIuYVSd/vNZ5TQBERlUoARERUKgEQEVGpBEBERKVaBYCktZL2SRqTtKnH9kWS7i/bd0kaLONLJD0o6SVJd3bts1DSZknflfSUpH8yExOKiIh2pnwXkKQ+4C7gY8BBYLekEdt7O8o2AEdsr5S0Hrgd+DXgGHAz8L7y0+nTwHO23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P8Mc093qad3MAzgMepfl0+o+A/u7HE8072C4vy/2lTrPc9zKaJ5iPAl+nuQvDvOm/9PIMcGHX2Lx4DNF8/unp7r/Hudz/Wf0KgN63sVg6Se1c9E7bz5blHwLvLMtzel7ldMIlwC7m0RzK6ZPHgeeAPwX+Evix7YlS0tnj625/Arx2+5PZ9Dngt4FXy/oS5lf/0Nyq6xuSHlFzGxiYP4+hFcA48HvlNNyXJJ3PHO7/bA+As4abfyLM+ffsSnor8IfAJ22/0Lltrs/B9gnbF9P8S3o18N5Zbqk1Sb8CPGf7kdnu5TR9yPalNKdHbpD04c6Nc/wx1A9cCtxt+xLgZX5+ugeYe/2f7QEw32858VeS3gVQ/nyujM/JeUk6h+bJ/8u2v1aG59UcAGz/GHiQ5pTJBWpubwKv73Gy25/Mlg8CvyrpGWArzWmgzzN/+gfA9qHy53PAH9EE8Xx5DB0EDtreVda30QTCnO3/bA+A+X7Lic5bbFxPc179tfHfKO8iuAw42vESc1ZIEs0nwp+0/bsdm+bFHCQNSLqgLJ9Lc/3iSZoguKaUdfff6/Yns8L2TbaX2R6keZzvtP1PmSf9A0g6X9LfeG0ZuAJ4gnnyGLL9Q+CApF8qQ2to7oIwd/ufrQsmZ+oH+GXguzTncz892/2cpM+vAM8CP6X5l8QGmnOy3wS+B/wZ8I5SK5p3N/0l8B1geA70/yGal7bfBh4vP788X+YA/B3gsdL/E8AtZfwXae5fNQZ8FVhUxt9S1sfK9l+c7f8GHXP5CPD1+dZ/6fUvys+e1/7/Ol8eQ6Wni4HR8jj6H8Db53L/uRVERESlzvZTQBERMYkEQEREpRIAERGVSgBERFQqARARUakEQEREpRIAERGV+v+7fLVJ6UqtUwAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pt7QwhdLJuvu",
        "outputId": "01b5e8b1-bcb5-4bd3-a32d-bd1288ae8793",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 230
        }
      },
      "source": [
        "score1 = model.evaluate(Xnormal_train, Xnormal_train)\n",
        "print(\"\\n Sample Loss(MAE) & Accuracy Scores (Train):\", score1[0], score1[1], \"\\n\") \n",
        "\n",
        "score2 = model.evaluate(Xnormal_test, Xnormal_test)\n",
        "print(\"\\nOut of Sample Loss(MAE) & Accuracy Scores (Test):\", score2[0], score2[1], \"\\n\") \n",
        "\n",
        "score3 = model.evaluate(Xattack, Xattack)\n",
        "print(\"\\nAttack Underway Loss(MAE) & Accuracy Scores (Anomaly):\", score3[0], score3[1], \"\\n\") "
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "2128/2128 [==============================] - 4s 2ms/step - loss: 0.0375 - accuracy: 0.4870\n",
            "\n",
            " Sample Loss(MAE) & Accuracy Scores (Train): 0.03754130378365517 0.48695167899131775 \n",
            "\n",
            "912/912 [==============================] - 2s 2ms/step - loss: 0.0482 - accuracy: 0.4840\n",
            "\n",
            "Out of Sample Loss(MAE) & Accuracy Scores (Test): 0.04821811988949776 0.4839803874492645 \n",
            "\n",
            "12399/12399 [==============================] - 24s 2ms/step - loss: 0.1700 - accuracy: 0.0047\n",
            "\n",
            "Attack Underway Loss(MAE) & Accuracy Scores (Anomaly): 0.16998399794101715 0.004738595802336931 \n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5SE9ZAAngTZg"
      },
      "source": [
        "**Conclusion:** The accuracy of model prediction on normal train and test sets is almost similarm aroung 0.48. Where as the model accuracy when trained on the anomaly or attack data is 0.0047 which is no way comaprable to the normal data accuracy. \n",
        "\n",
        "It is the same even with the loss, Mean Absolute Error (mae). The normal train and test sets have mae around 0.04 and the anomaly ot attack data has a mae of 0.16. From this we can detect the anomaly if any in the data. "
      ]
    }
  ]
}